package com.yjps.common.filter;

import com.yjps.common.util.ContantsUtil;
import org.apache.shiro.web.servlet.AdviceFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by jessy on 2015/8/28.
 */
public class ResponseAdviceFilter extends AdviceFilter {
    Logger log = LoggerFactory.getLogger(ResponseAdviceFilter.class);

    @Override
    protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
        Map map = ContantsUtil.init();
        request.setAttribute("map",map);
        return true;
    }

    @Override
    protected void postHandle(ServletRequest request, ServletResponse response) throws Exception {

    }

    @Override
    public void afterCompletion(ServletRequest request, ServletResponse response, Exception exception) throws Exception {
        log.debug("set  response header : Access-Control-Allow-Origin = * ");
        HttpServletResponse resp = (HttpServletResponse) response;
        resp.setHeader("Access-Control-Allow-Origin","*");
    }
}
